function hasPermission(permission, route) {
    if (route.meta && route.meta.title) {
        let flag = false
        for (let i = 0, len = permission.length; i < len; i++) {
            flag = route.meta.title.includes(permission[i]) || route.meta.title == '首页'
            if (flag) {
                return true
            }
        }
        return false
    }
    return true
}

function filterAsyncRouter(routerMap, roles) {
    const accessedRouters = routerMap.filter(route => {
        if (hasPermission(roles, route)) {
            if (route.children && route.children.length) {
                route.children = filterAsyncRouter(route.children, roles)
            }
            return true
        }
        return false
    })
    return accessedRouters
}

export default filterAsyncRouter